package hn.cch.mybatis.boot.provider;

import org.apache.ibatis.jdbc.SQL;

public class ScriptProvider {

    public String execute(String script) {
        return script;
    }

    public String getCountFromTable(String tableName, String dateField, String dateValue) {
        return new SQL() {{
            SELECT(" count(*) ");
            FROM(tableName);
            // WHERE(String.format(" %s = '%s' ", dateField, dateValue));
            WHERE(String.format(" %s=#{dateValue} ", dateField));
        }}.toString();
    }

    public String getCountByDateRange(String tableName, String dateField, String startDate, String endDate) {
        return new SQL() {{
            SELECT(" count(*) ");
            FROM(tableName);
            // WHERE(String.format(" %s between '%s' and '%s' ", dateField, startDate, endDate));
            WHERE(String.format(" %s between #{startDate} and #{endDate} ", dateField));
            GROUP_BY(dateField);
            ORDER_BY(dateField);
        }}.toString();
    }

}
